<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>tweetsearch.js 示例文件 | Qt Quick 5.11</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="../qtdoc/index.html">Qt 5.11</a></td><td ><a href="qtquick-index.html">Qt Quick</a></td><td ><a href="qtquick-demos-tweetsearch-example.html">Qt Quick Demo - Tweet Search</a></td><td >tweetsearch.js 示例文件</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right">Qt 5.11.1 参考指南</td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar"><div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">tweetsearch.js 示例文件</h1>
<span class="subtitle">demos/tweetsearch/content/tweetsearch.js</span>
<!-- $$$demos/tweetsearch/content/tweetsearch.js-description -->
<div class="descr"> <a name="details"></a>
<pre class="js">

  .pragma library

  <span class="keyword">function</span> <span class="name">formatDate</span>(<span class="name">date</span>)
  {
      var <span class="name">da</span> = new <span class="name">Date</span>(<span class="name">date</span>)
      <span class="keyword">return</span> <span class="name">da</span>.<span class="name">toDateString</span>()
  }

  <span class="keyword">function</span> <span class="name">demoToken</span>()
  {
      var <span class="name">a</span> = new <span class="name">Array</span>(<span class="number">22</span>).<span class="name">join</span>(<span class="string">'A'</span>)
      <span class="keyword">return</span> <span class="name">a</span> <span class="operator">+</span> <span class="name">String</span>.<span class="name">fromCharCode</span>(<span class="number">0x44</span>, <span class="number">0x69</span>, <span class="number">0x4a</span>, <span class="number">0x52</span>, <span class="number">0x51</span>, <span class="number">0x41</span>, <span class="number">0x41</span>, <span class="number">0x41</span>, <span class="number">0x41</span>,
                                     <span class="number">0x41</span>, <span class="number">0x41</span>, <span class="number">0x74</span>, <span class="number">0x2b</span>, <span class="number">0x72</span>, <span class="number">0x6a</span>, <span class="number">0x6c</span>, <span class="number">0x2b</span>, <span class="number">0x71</span>,
                                     <span class="number">0x6d</span>, <span class="number">0x7a</span>, <span class="number">0x30</span>, <span class="number">0x72</span>, <span class="number">0x63</span>, <span class="number">0x79</span>, <span class="number">0x2b</span>, <span class="number">0x42</span>, <span class="number">0x62</span>,
                                     <span class="number">0x75</span>, <span class="number">0x58</span>, <span class="number">0x42</span>, <span class="number">0x42</span>, <span class="number">0x73</span>, <span class="number">0x72</span>, <span class="number">0x55</span>, <span class="number">0x48</span>, <span class="number">0x47</span>,
                                     <span class="number">0x45</span>, <span class="number">0x67</span>, <span class="number">0x3d</span>, <span class="number">0x71</span>, <span class="number">0x30</span>, <span class="number">0x45</span>, <span class="number">0x4b</span>, <span class="number">0x32</span>, <span class="number">0x61</span>,
                                     <span class="number">0x57</span>, <span class="number">0x71</span>, <span class="number">0x51</span>, <span class="number">0x4d</span>, <span class="number">0x62</span>, <span class="number">0x31</span>, <span class="number">0x35</span>, <span class="number">0x67</span>, <span class="number">0x43</span>,
                                     <span class="number">0x5a</span>, <span class="number">0x4e</span>, <span class="number">0x77</span>, <span class="number">0x5a</span>, <span class="number">0x6f</span>, <span class="number">0x39</span>, <span class="number">0x79</span>, <span class="number">0x71</span>, <span class="number">0x61</span>,
                                     <span class="number">0x65</span>, <span class="number">0x30</span>, <span class="number">0x68</span>, <span class="number">0x70</span>, <span class="number">0x65</span>, <span class="number">0x32</span>, <span class="number">0x46</span>, <span class="number">0x44</span>, <span class="number">0x73</span>,
                                     <span class="number">0x53</span>, <span class="number">0x39</span>, <span class="number">0x32</span>, <span class="number">0x57</span>, <span class="number">0x41</span>, <span class="number">0x75</span>, <span class="number">0x30</span>, <span class="number">0x67</span>)
  }

  <span class="keyword">function</span> <span class="name">linkForEntity</span>(<span class="name">entity</span>)
  {
      <span class="keyword">return</span> (<span class="name">entity</span>.<span class="name">url</span> ? <span class="name">entity</span>.<span class="name">url</span> :
             (<span class="name">entity</span>.<span class="name">screen_name</span> ? <span class="string">'https://twitter.com/'</span> <span class="operator">+</span> <span class="name">entity</span>.<span class="name">screen_name</span> :
                                   <span class="string">'https://twitter.com/search?q=%23'</span> <span class="operator">+</span> <span class="name">entity</span>.<span class="name">text</span>))
  }

  <span class="keyword">function</span> <span class="name">textForEntity</span>(<span class="name">entity</span>)
  {
      <span class="keyword">return</span> (<span class="name">entity</span>.<span class="name">display_url</span> ? <span class="name">entity</span>.<span class="name">display_url</span> :
             (<span class="name">entity</span>.<span class="name">screen_name</span> ? <span class="name">entity</span>.<span class="name">screen_name</span> : <span class="name">entity</span>.<span class="name">text</span>))
  }

  <span class="keyword">function</span> <span class="name">insertLinks</span>(<span class="name">text</span>, entities)
  {
      <span class="keyword">if</span> (typeof <span class="name">text</span> <span class="operator">!==</span> <span class="string">'string'</span>)
          <span class="keyword">return</span> <span class="string">&quot;&quot;</span>;

      <span class="keyword">if</span> (!<span class="name">entities</span>)
          <span class="keyword">return</span> <span class="name">text</span>;

      // Add all links (urls, usernames and hashtags) to an array and sort them in
      // descending order of appearance in text
      var <span class="name">links</span> = []
      <span class="keyword">if</span> (<span class="name">entities</span>.<span class="name">urls</span>)
          <span class="name">links</span> <span class="operator">=</span> <span class="name">entities</span>.<span class="name">urls</span>.<span class="name">concat</span>(<span class="name">entities</span>.<span class="name">hashtags</span>, <span class="name">entities</span>.<span class="name">user_mentions</span>)
      <span class="keyword">else</span> <span class="keyword">if</span> (<span class="name">entities</span>.<span class="name">url</span>)
          <span class="name">links</span> <span class="operator">=</span> <span class="name">entities</span>.<span class="name">url</span>.<span class="name">urls</span>

      <span class="name">links</span>.<span class="name">sort</span>(<span class="keyword">function</span>(<span class="name">a</span>, b) { <span class="keyword">return</span> <span class="name">b</span>.<span class="name">indices</span>[<span class="number">0</span>] <span class="operator">-</span> <span class="name">a</span>.<span class="name">indices</span>[<span class="number">0</span>] })

      <span class="keyword">for</span> (<span class="keyword">var</span> <span class="name">i</span> = <span class="number">0</span>; <span class="name">i</span> <span class="operator">&lt;</span> <span class="name">links</span>.<span class="name">length</span>; i++) {
          var <span class="name">offset</span> = <span class="name">links</span>[<span class="name">i</span>].<span class="name">url</span> ? <span class="number">0</span> : <span class="number">1</span>
          <span class="name">text</span> <span class="operator">=</span> <span class="name">text</span>.<span class="name">substring</span>(<span class="number">0</span>, <span class="name">links</span>[<span class="name">i</span>].<span class="name">indices</span>[<span class="number">0</span>] <span class="operator">+</span> <span class="name">offset</span>) <span class="operator">+</span>
              <span class="string">'&lt;a href=\&quot;'</span> <span class="operator">+</span> <span class="name">linkForEntity</span>(<span class="name">links</span>[<span class="name">i</span>]) <span class="operator">+</span> <span class="string">'\&quot;&gt;'</span> <span class="operator">+</span>
              <span class="name">textForEntity</span>(<span class="name">links</span>[<span class="name">i</span>]) <span class="operator">+</span> <span class="string">'&lt;/a&gt;'</span> <span class="operator">+</span>
              <span class="name">text</span>.<span class="name">substring</span>(<span class="name">links</span>[<span class="name">i</span>].<span class="name">indices</span>[<span class="number">1</span>])
      }
      <span class="keyword">return</span> <span class="name">text</span>.<span class="name">replace</span>(/\n/g, <span class="string">'&lt;br&gt;'</span>);
  }

</pre>
</div>
<!-- @@@demos/tweetsearch/content/tweetsearch.js -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2018 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
